package gold.digger;

import gold.utils.InputUtil;

/**
 * Created by fanzhenyu02 on 2021/12/10.
 * common problem solver template.
 */
public class LC1576 {
    public long startExecuteTime = System.currentTimeMillis();


    class Solution {
        public String modifyString(String s) {
            StringBuilder res = new StringBuilder();
            for (int i = 0; i < s.length(); i++) {
                if (s.charAt(i) == '?') res.append(getReadyChar(i, s, res));
                else res.append(s.charAt(i));
            }

            return res.toString();
        }

        public char getReadyChar(int pos, String s, StringBuilder res) {
            if (s.length() == 1) return 'a';
            if (pos == 0) {
                for (char ch = 'a'; ch <= 'z'; ch++) if (ch != s.charAt(1)) return ch;
            } else if (pos == s.length() - 1) {
                for (char ch = 'a'; ch <= 'z'; ch++) if (ch != res.charAt(s.length() - 2)) return ch;
            } else {
                for (char ch = 'a'; ch <= 'z'; ch++)
                    if (ch != res.charAt(pos - 1) && ch != s.charAt(pos + 1)) return ch;
            }

            return 'z';
        }
    }

    public void run() {
        Solution solution = new Solution();
//        输入：s = "??yw?ipkj?"
//        输出："acywaipkja"
//        System.out.println(solution.modifyString("??yw?ipkj?"));
        System.out.println(solution.modifyString("??"));
    }

    public static void main(String[] args) throws Exception {
        LC1576 an = new LC1576();
        an.run();

        System.out.println("\ncurrent solution total execute time: " + (System.currentTimeMillis() - an.startExecuteTime) + " ms.");
    }
}
